package practise.mulitThreads.ChefAndWaiter;

import java.util.concurrent.Callable;

/**
 * Created by richard on 4/27/14.
 */
public class Chef implements Callable<Dinner> {
    private static volatile int cooked =0;
    private final static int COOK_TIME=1000;
    private Resturant resturant;
    public Resturant getResturant() {
        return resturant;
    }

    public void setResturant(Resturant resturant) {
        this.resturant = resturant;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    private Order order;
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    String name ;

    @Override
    public Dinner call() throws Exception {

        setOrder(getResturant().getOrderAndCook(this));


        getResturant().getChefs().remove(this);
        Dinner newDinner = new Dinner();
        newDinner.setName(getName()+":"+cooked+":"+getOrder());
        Thread.yield();
        Thread.sleep(COOK_TIME);


        getResturant().getChefs().add(this);
        return newDinner;
    }


}
